#!/bin/sh
#  script for qtsmbstatusd
#

# For LSB
### BEGIN INIT INFO
# Provides:          qtsmbstatusd
# Required-Start:    $samba
# Required-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: start qtsmbstatusd server at boot time
# Description:       QtSmbstatus is a graphical user interface for smbstatus
### END INIT INFO

# For Mandrake/Mandriva/Fedora:
# chkconfig: 35 99 20
# description: qtsmbstatusd server (QtSmbstatus is a graphical user interface for smbstatus)

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH
NAME=qtsmbstatusd

# see if qtsmbstatusd is running
pid=`ps ax | awk '{print $1,$5}' | grep $NAME | awk '{print $1}' | awk '{print $1}'`

# get locale
default_locale=en_US.UTF-8
if [ -f /etc/default/locale ]; then
        # Debian systems
        system_locale=`grep -re "LANG=" /etc/default/locale | awk 'BEGIN { FS = "[\"]" } { print $2 }'`
elif [ -f /etc/sysconfig/language ]; then
        # SuSE systems
        system_locale=`grep -re "LANG=" /etc/sysconfig/language | awk 'BEGIN { FS = "[\"]" } { print $2 }'`
elif [ -f /etc/sysconfig/i18n ]; then
        # RedHat/mandriva systems
        system_locale=`grep -re "LANG=" /etc/sysconfig/i18n | awk 'BEGIN { FS = "[\"]" } { print $2 }'`
elif [ -f /etc/profile ]; then
	#default
        system_locale=`grep -re "LANG=" /etc/profile | awk 'BEGIN { FS = "[\"]" } { print $2 }'`
fi

if [ -z $system_locale ]; then system_locale=$default_locale; fi

# Start or stop the qtsmbstatusd server
case $1 in
	start | restart | reload | force-reload)
		export LANG=$system_locale
		if test "$pid" != ""; then
			kill $pid
			if qtsmbstatusd -d; then
			echo "qtsmbstatusd server restarted."
			fi
                else
			if qtsmbstatusd -d; then
			echo "qtsmbstatusd server started."
			fi
		fi
                ;;
	stop)
		if test "$pid" != ""; then
		  kill -3 $pid
		fi
		echo "qtsmbstatusd server stopped"
		;;

	status)
		if test "$pid" != ""; then
			echo "qtsmbstatusd : server is running."
		else
			echo "qtsmbstatusd : server is not running."
		fi
		;;

	*)
		echo "Usage: qtsmbstatusd {start|stop|reload|restart|status|force-reload}"
		exit 1
		;;
esac

exit 0

